import { locale, loading, GraphNode, Action, ActionKey, rmi, validateRuleWindow } from "@/mdesign-lib/mdesign-app.umd.js";

export class ValidateConfigAction extends Action {
  keyName = ActionKey.validateConfig;

  desc = "校验模型";

  onTreeMenuClick(graphNode: any) {
    if (!graphNode) return;
    this.run(graphNode.id);
  }
  onSysMenuClick() {
    this.run();
  }
  async run(modelId?: string) {
    const project = app.activeProject;
    if (!project) return;

    validateRuleWindow.popup({ projectId: project.id, modelId }, async res => {
      if (res.success) {
        loading.popup(locale.t("校验中") + "...");
        if (res.checkStart) {
          await rmi.invokeAction(ActionKey.checkElementsByRules, res.params);
          validateRuleWindow.done();
          loading.close();
        }
      }
    });
  }
}
